//
//  AppDelegate.swift
//  LaiLang
//
//  Created by David on 2017/2/3.
//  Copyright © 2017年 David. All rights reserved.
//

import UIKit

let DOMAIN_NAME = "https://hcdstudio.cn"
let HJY_DOMAIN_NAME = "https://www.lailangzh.com"
let CACHES_PATH = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!
let DOCUMENT_PATH = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
let LLSavedLocationKey = "llocation"
let LLUserInfoKey = "lluserinfo"
let LLVerifyDurationKey = "llverifyduration"

let functionCollectionTitles = ["查课表","告白墙","缴电费","狼人杀","健身","上分","约拍","陪跑"]
let emptyPlaceholder = "这里啥都没有/(ㄒoㄒ)/~~"

let loginThemeColor = UIColor(r: 110, g: 213, b: 108)
let themeColor = UIColor(r: 250, g: 146, b: 55)

let passwordLegthMin = 6
let passwordLengthMax = 20
let verifyLength = 4

let dateFormat = "YYYY-MM-dd HH:mm:ss"

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    var firstVC: FirstViewController!
    var daoweiVC: DaoweiViewController!
    var moreVC: MsgViewController!
    var userVC: UserViewController!
    var loginVC: LoginViewController!
    

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        print(DOCUMENT_PATH)
        
        let tabController = UITabBarController()
        
        firstVC = FirstViewController()
        daoweiVC = DaoweiViewController()
        moreVC = MsgViewController()
        userVC = UserViewController()
        loginVC = LoginViewController()
        
        let firstNav = UINavigationController(rootViewController: firstVC)
        let daoweiNav = UINavigationController(rootViewController: daoweiVC)
        let moreNav = UINavigationController(rootViewController: moreVC)
//        let userNav = UINavigationController(rootViewController: loginVC)
        
        
//        let testVC = TestViewController()
//        let userNav = UINavigationController(rootViewController: testVC)
        
        firstNav.tabBarItem = UITabBarItem(title: "首页", image: #imageLiteral(resourceName: "home"), tag: 0)
        daoweiNav.tabBarItem = UITabBarItem(title: "到位", image: #imageLiteral(resourceName: "my-schedule"), tag: 1)
        moreNav.tabBarItem = UITabBarItem(title: "消息", image: #imageLiteral(resourceName: "msg"), tag: 2)
        loginVC.tabBarItem = UITabBarItem(title: "我", image: #imageLiteral(resourceName: "wode"), tag: 3)
        
//        let loginVC = LoginViewController()
//        loginVC.tabBarItem = UITabBarItem(title: "我", image: #imageLiteral(resourceName: "wode"), tag: 3)
//        let showUserVC = getUserInfo() == nil ? loginVC : userNav
        
        let showUserVC = loginVC
        
        let allNavVC: [UIViewController] = [firstNav, daoweiNav, moreNav, showUserVC!]
        tabController.setViewControllers(allNavVC, animated: false)
        
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.backgroundColor = UIColor.white
        window?.rootViewController = tabController
        window?.makeKeyAndVisible()
        
        do {
            //新建文件夹
            try FileManager.default.createDirectory(atPath: "\(CACHES_PATH)/slider", withIntermediateDirectories: true, attributes: nil)
            try FileManager.default.createDirectory(atPath: "\(CACHES_PATH)/activity", withIntermediateDirectories: true, attributes: nil)
            try FileManager.default.createDirectory(atPath: "\(CACHES_PATH)/msg", withIntermediateDirectories: true, attributes: nil)
            try FileManager.default.createDirectory(atPath: "\(CACHES_PATH)/msg/image", withIntermediateDirectories: true, attributes: nil)
            try FileManager.default.createDirectory(atPath: "\(DOCUMENT_PATH)/kebiao", withIntermediateDirectories: true, attributes: nil)
        } catch let err {
            print(err)
        }
        
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }

    

}

func getUserInfo() -> Any? {
    return UserDefaults.standard.object(forKey: LLUserInfoKey)
}

extension UIColor {
    convenience init(hex: Int){
        self.init(red: CGFloat((hex & 0xFF0000) >> 16) / 255.0,
                  green: CGFloat((hex & 0x00FF00) >> 8) / 255.0,
                  blue: CGFloat(hex & 0x0000FF) / 255.0,
                  alpha: CGFloat(1.0))
    }
    convenience init(r: Int, g: Int, b: Int){
        self.init(red: CGFloat(r)/255.0, green: CGFloat(g)/255.0, blue: CGFloat(b)/255.0, alpha: 1)
    }
    convenience init(r: Int, g: Int, b: Int, a: CGFloat){
        self.init(red: CGFloat(r)/255.0, green: CGFloat(g)/255.0, blue: CGFloat(b)/255.0, alpha: a)
    }
}

let JZMajorList = ["艺术系", "中文系", "公共管理系", "工商管理系","国贸金融系","物流系","机械系","电子系","计算机系","外语系","化药系","建筑系","音乐舞蹈学院","继续教育学院"]
let homeTopicImgSize:CGFloat = 80.0
